﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using Datalayer;
using Common;
using System.Data;

namespace Portal_KonTum
{
    public partial class ViewNews : System.Web.UI.Page
    {
        IQueryMgr iq;
        protected void Page_Load(object sender, EventArgs e)
        {
            BinData();
        }
        void BinData()
        {
            string id = Request.QueryString["NewID"];
            New ex = new New();
            string s = "";
            iq = QueryMgr.GetDbInstance();
            try
            {
                    Guid idc = new Guid();
                    idc = MethodCommon.Get_Guid(id);
                    ex = iq.News_GetNewByID(idc);
                    //facebook,google,in
                    hlfacebook.NavigateUrl = "https://www.facebook.com/sharer/sharer.php?u="+ Request.Url;
                    hlgoogle.NavigateUrl = "https://www.google.com/bookmarks/mark?op=edit&amp;bkmk=" +Request.Url;
                    hlprint.NavigateUrl = "~/PrintNews.aspx?ID="+id;
                    //
                    lblCateName.Text = ex.Category.CategoryName; 
                    lblCreateBy.Text =" Người đăng:"+ ex.User.FullName;
                    lblContent.Text = ex.NewContent;
                    lblDatecreate.Text =" Ngày đăng:"+ ex.CreateDate.ToString();
                    lblIntro.Text = ex.NewIntro;
                    lblTitle.Text = ex.NewTitle;
                    lblHit.Text = " Số lượt xem:" +ex.Hit;
                    if (ex.Source != "")
                    {
                        lblSource.Text = "Theo "+ex.Source;
                    }

                    //load các bài viết cùng danh mục
                    List<New> listnew = new List<New>();
                    listnew = iq.News_GetNewByCatID(ex.CateID);
                    int i = 0; 
                    foreach (New news in listnew)
                    {
                        if (i == 5)
                            break;
                        s = s + "<li class='sub'><a href='ViewNews.aspx?NewID=" + news.NewID + "'>" + news.NewTitle + "</a></li>";
                        i++;
                    }
            
                lblOther.Text = s;
                //tăng số lượt xem
                iq.News_Hit(ex.NewID);

            }
            catch (Exception exa)
            {
                Alert.Show(exa.ToString());
            }
        }
    }
}